<template>
  <div class="announcement-container">
    <div class="announcement-search">
      <el-form
        ref="queryForm"
        :model="queryParams"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="标题" >
          <el-input
            v-model="queryParams.title"
            placeholder="公告标题"
            clearable
            size="medium"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="medium"
            @click="handleQuery"
          >搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="announcement-list">
      <el-table v-loading="loading" :data="announcementList" @cell-click="clickCell">
        <el-table-column label="标题" align="center" >
          <template slot-scope="scope">
            <el-link>{{scope.row.title}}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="分类" prop="categoryName" align="center">

        </el-table-column>
        <el-table-column label="浏览次数" prop="viewCount" align="center">

        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center">

        </el-table-column>
      </el-table>
      <el-pagination
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-sizes="[10, 20, 30, 40]"
        :current-page.sync="queryParams.pageNum"
        @current-change="getList"
        @size-change="getList"
      />
    </div>
  </div>
</template>

<script>
  import {getAnnouncement} from "../api/article/article";

  export default {
      name: "Announcement",
      data() {
        return {
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            title: ''
          },
          total: 0,
          loading: true,
          announcementList: []
        }
      },
    created() {
      document.title = '社区公告'
    },
    methods: {
      handleQuery() {
        this.getList()
      },
      getList() {
        this.queryParams.pageNum = 1
        this.loading = true
        getAnnouncement(this.queryParams).then((res) => {
          this.announcementList = res.rows
          this.total = res.total
          this.loading = false
        })
      },
      clickCell(row) {
        this.$router.push({name: 'AnnouncementDetail', query: {aid: row.id}})
      }
    },
    mounted() {
        this.getList()
    }
  }
</script>

<style scoped>
  .announcement-container {
    width: 90%;
    margin: 0 auto;
  }
  .announcement-search {
    box-shadow: 0 0 15px #b6b5b5;
    background-image: linear-gradient(to top, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%);
    border-radius: 2vh;
    padding: 5vh;
    margin-top: 20px;
  }
  .announcement-search /deep/ .el-form-item {
    margin-bottom: 0;
  }
  .header-image {
    width: 100%;
    height: 30vh;
    border-radius: 5vh;
  }
  .announcement-list {
    margin-top: 50px;
    height: 60vh;
    box-shadow: 0 0 15px #b6b5b5;
    padding: 5vh;
    border-radius: 5vh;
    background-image: linear-gradient(to top, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%);
  }
</style>
